#include "StaticDataManager.h"
#include "DataInfoManagerContainer.h"
#include <set>
#include <tinyxml/tinyxml.h>

CStaticDataManager::CStaticDataManager()
{
}

CStaticDataManager::~CStaticDataManager()
{

}

void CStaticDataManager::LoadAllData()
{
	Logger& rLogger = Logger::GetInstance("StaticData");
	std::set< std::string > fileSet;
	std::string strFilePath = "StaticData/";
	TiXmlDocument doc("StaticData/StaticTableMap.xml");
	if (doc.LoadFile())
	{
		TiXmlNode * pTableMapNode = doc.FirstChild("TableMap");
		if (pTableMapNode)
		{
			TiXmlElement * pItemE = pTableMapNode->FirstChildElement("Item");
			for(; pItemE; pItemE = pItemE->NextSiblingElement("Item"))
			{
				std::string strFileName = strFilePath + pItemE->Attribute("FileName");
				strFileName = strFileName.substr(0, strFileName.find_last_of('.')) + ".dat";
				fileSet.insert(strFileName);
			}
		}
		else
		{
			LOG_WARN(rLogger, "There is something wrong with the file of StaticData/StaticTableMap.xml");
		}
	}
	else
	{
		LOG_ERROR(rLogger, "Load StaticData/StaticTableMap.xml Failed.");
	}
	std::set< std::string >::iterator it = fileSet.begin();
	for (; it!=fileSet.end(); ++it)
	{
		CDataInfoManagerContainer::Instance().LoadFromFile(*it);
	}
	//std::string strFilePath = "StaticData/";
	//CDataInfoManagerContainer::Instance().LoadFromFile(strFilePath + "ItemList.dat");
	//CDataInfoManagerContainer::Instance().LoadFromFile(strFilePath + "ItemList2.dat");
	//CDataInfoManagerContainer::Instance().LoadFromFile(strFilePath + "ItemList3.dat");
	//CDataInfoManagerContainer::Instance().LoadFromFile(strFilePath + "XXXX.dat");
}
